package com.oa.service.impl;

import com.oa.vo.Page;
import com.oa.pojo.Department;
import com.oa.mapper.DepartmentMapper;
import com.oa.service.DepartmentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    DepartmentMapper departmentMapper;

    @Override
    public void addDepartment(Department department) {
        departmentMapper.addDepartment(department);
    }

    @Override
    public void delDepartment(Integer departmentId) {
        departmentMapper.delDepartment(departmentId);
    }

    @Override
    public void updateDepartment(Department department) {
        departmentMapper.updateDepartment(department);
    }

    @Override
    public List<Department> getDepartmentList() {
        return departmentMapper.getDepartmentList();
    }

    @Override
    public Page getDepartmentPage(Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<Department> departmentList = departmentMapper.getDepartmentList();
        Page page = new Page();
        PageInfo<Department> pageInfo = new PageInfo<>(departmentList);
        page.setPageCount(pageInfo.getPages());
        page.setCount(pageInfo.getTotal());
        page.setObject(pageInfo.getList());
        return page;
    }

    @Override
    public Department getDepartment(Integer deptId) {
        return departmentMapper.getDepartment(deptId);
    }


}
